package com.example.utils;

import android.text.Editable;
import android.text.TextWatcher;

import java.util.function.Consumer;

public class AccountAutoTipTextWatcher implements TextWatcher {
    private final int length;
    private final Consumer<String> accountConsumer;

    public AccountAutoTipTextWatcher(int length, Consumer<String> accountConsumer) {
        this.length = length;
        this.accountConsumer = accountConsumer;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {

        if(s.length()==length){
            accountConsumer.accept(s.toString());
        }
    }
}
